package com.ec.bl.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ec.bl.domain.dto.BillQueryDTO;
import com.ec.api.domain.po.Bill;
import com.ec.bl.domain.vo.BillQueryVO;
import com.ec.bl.domain.vo.BillWithDetailsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface BillMapper extends BaseMapper<Bill> {

    /**
     * 分页查询账单信息
     * @param page 分页对象
     * @param queryDTO 查询条件
     * @return 账单查询结果
     */
    IPage<BillQueryVO> selectBillPage(Page<BillQueryVO> page, @Param("query") BillQueryDTO queryDTO);

    /**
     * 根据账单ID查询账单基本信息（包含老人姓名）
     */
    @Select("SELECT b.id, b.elderly_user_id, ep.full_name as elderly_name, " +
            "b.bill_month, b.total_amount, b.status, b.due_date, b.paid_at, " +
            "b.created_by_admin_id, b.created_at " +
            "FROM bills b " +
            "LEFT JOIN elderly_profiles ep ON b.elderly_user_id = ep.user_id " +
            "WHERE b.id = #{id}")
    BillWithDetailsVO selectBillWithElderlyInfo(Long id);
}